<?php
namespace Common\Controller;
use Base\Controller;
class WeixinController extends Controller {
	var $user;
	protected  function _initialize(){
		parent::_initialize();
		//测试用
		if (get_client_ip()=='27.16.128.120'){
			//$_SESSION["open_id"]='ovuzos_YVGHWTb8uI5OfBYuvm5c8';
			//unset($_SESSION["user"]);
		}
		if (empty($_SESSION["open_id"])){
			$_SESSION["back_url"]=__SELF__;
			$url=U('Weixin/login');
			redirect($url);
			return false;
		}else{
			$this->open_id=$_SESSION["open_id"];
			if (!$_SESSION["user"]){
				$_SESSION["user"] = R ( "Api/Api/getuser", array (
						$this->open_id 
				) );
				$_SESSION["uid"]=$_SESSION["user"]['UserId'];
				cookie('uid',$_SESSION["user"]['UserId']);
			}
			if (!$_SESSION["uid"]){
				$_SESSION["back_url"]=__SELF__;
				$url=U('Weixin/login');
				redirect($url);
				return false;
			}
			$this->uid=$_SESSION["user"]['UserId'];
			$this->user=$_SESSION["user"];
			$this->user_type=$_SESSION["user"]['UserType'];
			$this->assign("UserType",$this->user_type);
		}
		//dump($this->cart->return_cart_info());
		$this->assign ( "user", $this->user );
    }

}
